// t_add
define(['jquery','twoJs'],function($,twos){
    var t_add={
        init:function(){
            //点击返回专题列表页面
            $("#ta-fanhui").click(function(){
                $(".ta-box").hide();
                var obj={"htmlname":"twoHtml","cssname":"twoCss","jsname":"twoJs"};
                $(this).attr({"htmlname":""+obj.htmlname+"","cssname":""+obj.cssname+"","jsname":""+obj.jsname+""});
                var html=$(this).attr("htmlname");
                var css=$(this).attr("cssname");
                var js=$(this).attr("jsname");
                //console.log(html,css,js)
                $(".con-position").show();
                setTimeout(function(){
                    $(".con-position").hide();
                    require(['requireText!'+html,'requireCss!'+css,js],function(html,css,js){
                        $(".con-bottom").html(html);
                        twos.tadd();
                        //console.log($(".t-table tbody tr").length);
                        //js.init();
                        return false;
                    });
                },200);

            });
        //    上传图片
            var q;
            $("#files").change(function(){
                upload(this);
                $(this).parent().parent().next().find("img").attr("src",""+q+"");

            });
            function upload(obj){
                //console.log(obj.files.length);
                /*
                * 创建文件路径 二进制,单个需要加下标  否则报错,obj.files.name   获取文件名字
                * */
                q=window.URL.createObjectURL(obj.files[0]);
                var txt=obj.files[0].name;
            }
        //  点击插入到页面上
            var random=Math.floor(Math.random()*100000);
            if (random < 10000) {
                return false;
            }
            var zhuangtai=["已发布","未发布"];
            var num="0";
            var ta_td,ta_td2,time,full,month,date,months,dates;
            var agelosr=sessionStorage.getItem("zhusir");
            var lastdiv = "<div class='t-last'><div>♞ 制作</div><div>❂ 编辑</div><div>☂ 编辑数据</div><div>✿ 块管理</div><div>☯ 改为新版js</div><div>➹ 删除</div></div>";
            var check = "<input type='checkbox'>";
            var box = "<td style='position: relative;' class='t-lasttd'><span class='t-suoding'>✘锁定</span><span class='t-caozuo' style='color:#337ab7;'>操作 ▼</span>" + lastdiv + "</td>";
            // 页面发布时间
            function times(){
                time=new Date();
                full=time.getFullYear();
                month=time.getMonth()+1;
                date=time.getDate();
                months=(month<=9)?num+month:month;
                dates=(date<=9)?num+date:date;
                ta_td=""+full+"-"+months+"-"+dates+"";
                ta_td2=""+full+"-"+months+"-"+(Number(((date<=9)?num+date:date) - 1))+"";
                return [ta_td,ta_td2];
            }
            setInterval(times(),1000);
            //console.log(ta_td)

            //  点击插入到页面上
            var req=/\s/,input1,input2,input3,input4,input5;
            $("#ta-submit").on("click",function(e){
                e.preventDefault();
                // 判断输入是否为空
                if($(".ta-inset-li1 input").val() == "" || req.test($(".ta-inset-li1 input").val())){
                    alert("专题名输入不能为空或空格！");
                    return false;
                } else if($(".ta-inset-li2 input").val() == "" || req.test($(".ta-inset-li2 input").val())){
                    alert("专题名英文输入不能为空或空格！");
                    return false;
                }else if($(".ta-inset-li6 input").val() == ""){
                    $(".ta-inset-li6 input").val("未知")
                } else if($(".ta-inset-li4 select").val() == $(".ta-inset-li4 select").find("option:first-child").val()){
                    alert("请选择客户端！");
                    return false;
                } else if($(".ta-inset-li5 select").val() == $(".ta-inset-li5 select").find("option:first-child").val()){
                    alert("请选择专题类型！");
                    return false;
                }
                input1=$(".ta-inset-li1 input").val();
                input2=$(".ta-inset-li2 input").val();
                input3=$(".ta-inset-li6 input").val();
                input4=$(".ta-inset-li4 select").val();
                input5=$(".ta-inset-li5 select").val();
                $(".ta-box").hide();
                var obj={"htmlname":"twoHtml","cssname":"twoCss","jsname":"twoJs"};
                $(this).attr({"htmlname":""+obj.htmlname+"","cssname":""+obj.cssname+"","jsname":""+obj.jsname+""});
                var html=$(this).attr("htmlname");
                var css=$(this).attr("cssname");
                var js=$(this).attr("jsname");
                //console.log(html,css,js)
                $(".con-position").show();
                setTimeout(function(){
                    $(".con-position").hide();
                    require(['requireText!'+html,'requireCss!'+css,js],function(html,css,js){
                        $(".con-bottom").html(html);
                        twos.tadd();
                        $(".t-table tbody").append("<tr><td first1='hunbohui'>"+check+""+random+"</td><td first2='badajie'><a href='https://www.baidu.com/' style='color:#5494f0;' target='_blank'>"+input1+"</a></td><td first3='sheying'>"+input2+"</td><td>"+zhuangtai[Math.floor(Math.random()*2)]+"</td><td style='color:#5494f0;'>"+input3+"</td><td>"+input4+"</td><td>"+input5+"</td><td>"+ta_td2+"</td><td>"+ta_td+"</td><td>我是测试不要打电话</td><td>"+agelosr+"</td><td>--</td>"+box+"</tr>");

                        return false;
                    });
                },200);
            });



        }

    };      //   init end
    return t_add;
});